package se.gala.games.quetzalcoatl;

import se.gala.api.APICommand;
import se.gala.api.GenericAPICommands;
import se.gala.api.GenericParameters;
import se.gala.utils.GGObject;

public class DefaultResponseHandler extends GGObject implements ClientCommandRequestor {
	
	private static DefaultResponseHandler selfInstance;
	
	private DefaultResponseHandler() {
		DefaultResponseHandler.selfInstance = this;
	}
	
	public static DefaultResponseHandler getInstance() {
		if (DefaultResponseHandler.selfInstance == null) {
			new DefaultResponseHandler();
		}
		return DefaultResponseHandler.selfInstance;
	}
	
	public void handleResponseCommand(APICommand command) {
		int cid = command.getId();
		
		if (GenericAPICommands.isGenericAPICommand(cid)) {
			GenericAPICommands r = GenericAPICommands.getCommandById(cid);
			switch (r) {
			case Authenticate_Response_Successful :
				UIQuetzalcoatl.setPlayer((String) command.getParamValue(GenericParameters.SessionToken.getParamName()));
			break;
			case MalformattedCommand_Error:
			case Authenticate_Response_Error :
				log("BAD ERROR: " + command.getKey(), LogLevel.Error);
				break;
			default:
				log("WE DON'T SUPPORT YET COMMAND: " + command.getKey(), LogLevel.Warning);
				break;
			}
		} else {
			// TODO handle non generic commands
		}
	}

}
